#include<stdio.h>
#include<stdlib.h>

ssize_t my_getline(char **lineptr, size_t *n, FILE *stream);
int main(int argc, char * argv[])
{
	if(argc < 2){
		return -1;
	}
	FILE *fp = fopen(argv[1], "r");
	if(fp == NULL){
		return 1;
	}
	size_t n = 0;
	char *lineptr = NULL;
	my_getline(&lineptr, &n, fp);
	
	puts(lineptr);

	return 0;
}

ssize_t my_getline(char **lineptr, size_t *n, FILE *stream)
{
	int i = 0;
	while(1){
		*lineptr = realloc(*lineptr, i + 1);
		if(*lineptr == NULL){
			return -1;
		}
	   	*(*lineptr + i) = fgetc(stream);

		if(*(*lineptr + i) == '\n'){
			*(*lineptr + i) = '\0';
			break;
		}
		i++;
	}
	*n = i + 1;
	return *n;
}
